package com.music.muisc.controllers;

import com.music.muisc.dao.ForumRepository;
import com.music.muisc.dao.InteractionRepository;
import com.music.muisc.dao.MusicRepository;
import com.music.muisc.dao.UnitRepository;
import com.music.muisc.dto.MusicQuantity;
import com.music.muisc.dto.UnitMusic;
import com.music.muisc.entity.Forum;
import com.music.muisc.entity.Interaction;
import com.music.muisc.entity.Music;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {
    @Value("${version}")
    private String version;
    @Autowired
    MusicRepository musicRepository;

    @Autowired
    UnitRepository unitRepository;

    @Autowired
    ForumRepository forumRepository;

    @Autowired
    InteractionRepository interactionRepository;


    @GetMapping("/")
    public String displayHome(Model model){
        model.addAttribute("versionNumber",version);

        List<Music> musics = musicRepository.findAll();
        model.addAttribute("musics",musics);//通过Model对象将数据传至视图层，即HTML模板中


        List<UnitMusic> unitMusics = unitRepository.unitMusics();
        model.addAttribute("unitMusics", unitMusics);

        List<MusicQuantity> musicQuantities = musicRepository.musicQuantities();
        model.addAttribute("musicQuantities", musicQuantities);

        List<Forum> forums =  forumRepository.findAll();
        model.addAttribute("forums",forums);


        List<Interaction> interactions = interactionRepository.findAll();
        model.addAttribute("interactions", interactions);


        return "main/home";

    }
}
